package com.xxxx.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @Author Str
 * @Date 2021/9/28 16:46
 * @Description :
 */
@Controller
public class RestFulController {

    @RequestMapping("/add")
    public String test1(Model model, int a, int b) {
        int res = a + b;
        model.addAttribute("msg", "结果为：" + res);
        return "hello";
    }

    // @PathVariable路径变量
    @RequestMapping("/add2/{a}/{b}")
    public String test2(Model model, @PathVariable int a, @PathVariable int b) {
        int res = a + b;
        model.addAttribute("msg", "结果为：" + res);
        return "hello";
    }

    // method = RequestMethod.GET限定了只能通过get方式请求
    @RequestMapping(value = "/add3/{a}/{b}", method = RequestMethod.GET)
    public String test3(Model model, @PathVariable int a, @PathVariable int b) {
        int res = a + b;
        model.addAttribute("msg", "结果为：" + res);
        return "hello";
    }
    @RequestMapping("/t4")
    public String test4(){
        //转发一
        return "/WEB-INF/jsp/a.jsp";
    }

    @RequestMapping("/t5")
    public String test5(){
        //转发二
        return "forward:/WEB-INF/jsp/a.jsp";
    }

    @RequestMapping("/t6")
    public String test6(){
        //重定向
        return "redirect:/index.jsp";
    }
}
